/*
 * @Author: song
 * @Description:红点挂点
 * @Date: 2024年04月14日 星期日 17:04:39
 * @Modify:
 */

using UnityEngine;

namespace Function.RedPoint
{
    public class RedPointView : MonoBehaviour
    {
        public SRedPointType _pointType;
        public Transform _goRed;

        private void OnEnable()
        {
            var node = RedPointSystem.Instance.AddRedPoint(this);
            Execute(node); //显示的时候 默认刷一遍
            if (_goRed == null)
            {
                _goRed = transform.Find("_goRed");
            }

            RedPointSystem.Instance.RefreshRedPoint(_pointType);
        }

        private void OnDisable()
        {
            RedPointSystem.Instance.RemoveRedPoint(this);
        }

        public void Execute(RedPointNode node)
        {
            if (_goRed == null)
            {
                ($" {_pointType} dont" + $" bind red view").Error();
                return;
            }

            _goRed.localScale =
                node._num >= 1 ? Vector3.one : Vector3.zero;
        }
    }
}